// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   PostTagRepositoryJdbc.java

package dale.web.post.repository;

import dale.web.post.domain.Post;
import dale.web.post.domain.PostTag;
import dale.web.tag.domain.Tag;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.*;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

// Referenced classes of package dale.web.post.repository:
//            PostTagRepository

public class PostTagRepositoryJdbc
    implements PostTagRepository
{

    public PostTagRepositoryJdbc(DataSource dataSource)
    {
        template = new NamedParameterJdbcTemplate(dataSource);
        insert = new SimpleJdbcInsert(dataSource);
        insert.withTableName("post_tag");
        mapper = new BeanPropertyRowMapper();
    }

    public void insert(PostTag item)
    {
        SqlParameterSource param = new BeanPropertySqlParameterSource(item);
        int count = insert.execute(param);
        if(count != 1)
            throw new RuntimeException("No rows were inserted.");
        else
            return;
    }

    public List list(Post post)
    {
        String sql = "SELECT * FROM post_tag\nWHERE postNo = :postNo\n";
        SqlParameterSource param = post == null ? null : ((SqlParameterSource) (new BeanPropertySqlParameterSource(post)));
        return template.query(sql, param, mapper);
    }

    public int delete(int no)
    {
        String sql = "DELETE FROM post_tag\nWHERE postNo = :postNo\n";
        MapSqlParameterSource param = new MapSqlParameterSource();
        param.addValue("postNo", Integer.valueOf(no));
        return template.update(sql, param);
    }

    private static final String SELECT = "SELECT * FROM post_tag\n";
    private static final String DELETE = "DELETE FROM post_tag\n";
    private static final String WHERE = "WHERE postNo = :postNo\n";
    private NamedParameterJdbcTemplate template;
    private SimpleJdbcInsert insert;
    private RowMapper mapper;
}
